<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <h1>Page LocalStorage</h1>
    </div>

    <script>
        //存储数据
        var name = 'localData';
        var num = 120;
        localStorage.setItem(name, num);
        localStorage.setItem('value2', 119);

        //获取全部数据
        let dataAll = localStorage.valueOf();
        console.log(dataAll, '获取全部数据');

        //获取指定键名数据
        var datalocal = localStorage.getItem(name);
        //localStorage是js对象，也可以使用key的方式来获取值
        var datalocal2 = localStorage.localData;
        console.log(datalocal, datalocal2, '获取指定键名数据');

        //删除指定键名数据
        localStorage.removeItem(name); 
        console.log(dataAll, '获取全部数据1');

        //清空缓存数据
        // localStorage.clear();
        // console.log(dataAll, '获取全部数据2');
    </script>
</body>

</html>